home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / SpriteWorld 2.2 / SpriteWorld Examples / Scrolling Demo / Scrolling Demo Read Me < prev    next >
Encoding:
Text File  |  1998-07-09  |  5.0 KB  |  45 lines  |  [TEXT/ttxt]

  1. This is a rather simple project that demonstrates how to use the scrolling and tiling routines. The code is very similar to the code used for non-scrolling SpriteWorlds, and is not really any harder to set up. Use the numeric keypad or the arrow keys to move your ball around on the screen.
  2.  
  3. This program demonstrates some of the special effects that can be accomplished when using the tiling routines, such as having tiles that change frames (the diamond and wall tiles), and tiles that appear in front of your sprites. If you scroll down far enough, you can find the tiles that appear above your sprite. Move under the bridge to get to the other side, where your sprite can move under the "wire" tiles. It's a pretty neat effect, and shows how you can make games that have psudo-3D landscapes by having some tiles appear above your sprites.
  4.  
  5. This demo is limited to 30fps so that the sprite isn't too hard to control on faster Macs. If you want to see how fast it can really go, try setting kMaxFPS (a #defined value at the beginning of Scrolling Demo.c) to 0, which tells SpriteWorld to let the animation run as fast as it can. Also, for maximum speed, try running in either 256 colors or in B&W. The FPS report given at the end of the animation isn't completely accurate - it may be off by a few FPS one way or the other.
  6.  
  7. This demo is actually a bare-bones version of a game I'm planning on making in the near future. Look for the title "Diamond Digger" in a year or two.
  8.  
  9.  
  10. * Update *
  11.  
  12. With the release of SpriteWorld 2.1, I've added a new feature - a "meter" that measures how many diamonds you've collected. The purpose of this meter was to demonstrate how to add a sprite to the animation that must remain at a fixed position on the screen, even while scrolling. This is first accomplished by making a MoveProc that moves the sprite to the current visScrollRect location plus wherever you want the sprite to appear on the screen:
  13.  
  14. SW_FUNC void DiamondMeterSpriteMoveProc(SpritePtr srcSpriteP)
  15. {
  16.     SWMoveSprite(srcSpriteP,  gSpriteWorldP->visScrollRect.left + 10, 
  17.             gSpriteWorldP->visScrollRect.top + 10);
  18. }
  19.  
  20. However, there is a problem: SWProcessScrollingSpriteWorld processes the sprites before moving the visScrollRect. It does this so the ScrollingWorldMoveProc will have the latest position of whatever sprite it is following. However, this means that when our DiamondMeterSpriteMoveProc is called, it will be using the visScrollRect value from the previous frame, since the visScrollRect hasn't been moved yet. The solution is to not install the MoveProc in the sprite, but rather to call it yourself after calling  SWProcessScrollingSpriteWorld, but before calling SWAnimateScrollingSpriteWorld:
  21.  
  22.     while (!Button())
  23.     {
  24.         SWProcessScrollingSpriteWorld(gSpriteWorldP);
  25.         
  26.             // Move diamond meter sprite to new visScrollRect location
  27.         DiamondMeterSpriteMoveProc(gDiamondMeterSpriteP);
  28.     
  29.         SWAnimateScrollingSpriteWorld(gSpriteWorldP);
  30.         
  31.         if (gSpriteWorldP->frameHasOccurred)
  32.             frames++;
  33.     }
  34.  
  35. There is yet another trick this program now demonstrates, and that is how to modify a sprite's image and mask while the program is running. To see how this is done, take a look at the UpdateDiamondMeter function. Notice that the sprite's needsToBeDrawn flag is set to true whenever the sprite's image is changed. Keep in mind that this is an idle sprite, only moving whenever the screen scrolls. (Keep in mind that the sprite does move when the screen scrolls, even though it appears to remain in a fixed position on the screen.) Although the screen usually scrolls whenever you pick up a diamond, there is an instance in the demo where you could pick up a diamond without the screen scrolling, and the meter would be updated offscreen, but the sprite would not be redrawn on the screen, since SpriteWorld thinks the sprite is idle and hasn't changed. This is why we must tell SpriteWorld that is has changed, by setting the needsToBeDrawn flag to true.
  36.  
  37. In general, it's a good idea to set the needsToBeDrawn flag to true whenever you make a change to a sprite that SpriteWorld doesn't know about, even if you think the flag will be set to true by SpriteWorld anyway, since sometimes it might not be. One example would be if you set a MoveTime for a sprite - the sprite may move some frames and not others. When it doesn't move, SpriteWorld will try to save time by not drawing it. And if you'd make a change to the sprite that SpriteWorld didn't know about, and you didn't set the needsToBeDrawn flag to true, the sprite won't get updated.
  38.  
  39. For more information about changing a Sprite's image and pixelMask, see the sections "Modifying a Sprite's image" and "Modifying a Sprite's pixelMask" in the SpriteWorld Tips and Tricks file.
  40.  
  41. Another Update
  42.  
  43. With the 2.2 release of SpriteWorld, the diamond meter sprite now appears behind the masked wire tiles in the bottom half of the demo. Although I could change this by creating a new spriteLayer that's not below the first tile layer and adding the diamond meter sprite to that layer. However, I thought the effect was pretty neat, so I left it that way. :-)
  44.  
  45. -Vern